using Godot;
using Godot.Collections;

namespace GoGameClient.script.node.mouse;

public partial class MouseControl : CanvasLayer
{
    // Called when the node enters the scene tree for the first time.
    private AnimatedSprite2D _mouse;
    private static MouseControl _instance;
    private MouseMode _mode = MouseMode.默认;

    public static MouseControl Instance()
    {
        return _instance;
    }

    public override void _Ready()
    {
        _instance = this;
        Input.MouseMode = Input.MouseModeEnum.Hidden;
        _mouse = GetNode<AnimatedSprite2D>("Mouse");
    }

    public override void _Input(InputEvent @event)
    {
        switch (@event)
        {
            case InputEventMouseMotion eventMouseMotion:
                _mouse.Position = eventMouseMotion.Position+ new Vector2(16, 16);
                break;
            case InputEventMouseButton { Pressed: true }:
                if (_mode != MouseMode.默认)
                    SetMouseMode(MouseMode.默认);
                break;
        }
    }


    public void SetMouseMode(MouseMode mode)
    {
        _mouse.Animation = _mouseModeMapping[mode];
        _mode = mode;
    }

    Dictionary<MouseMode, string> _mouseModeMapping = new()
    {
        { MouseMode.默认, "default" },
        { MouseMode.攻击, "attack" },
        { MouseMode.道具, "item" },
        { MouseMode.捕捉, "capture" },
        { MouseMode.保护, "protect" },
        { MouseMode.禁止, "forbid" },
        { MouseMode.输入, "input" },
        { MouseMode.事件, "event" },
        { MouseMode.组队, "team" },
        { MouseMode.交易, "trade" },
        { MouseMode.给予, "give" },
        { MouseMode.好友, "friend" },
        { MouseMode.拆分, "split" }
    };


    public enum MouseMode
    {
        默认,
        攻击,
        道具,
        捕捉,
        保护,
        禁止,
        输入,
        事件,
        组队,
        交易,
        给予,
        好友,
        拆分
    }
}